package com.example.manager.controller;

import com.example.manager.service.UserService;
import com.example.manager.pojo.Code;
import com.example.manager.pojo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/manager/users")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private HttpSession httpSession;

    @PostMapping("/login")
    public Result Login(String username, String password) {
        Result result = userService.login(username, password);
        if (result.getCode() == Code.RESPONSE_CODE_SUCCESS) {
            httpSession.setAttribute("username", username);
        }
        return result;
    }
}
